public class Solution926 {
    public int minFlipsMonoIncr(String s) {
        int[] f=new int[s.length()];
        f[0]=s.charAt(0)=='0'?0:1;
        for (int i=1;i<s.length();i++){
            f[i]=f[i-1]+(s.charAt(i)=='0'?0:1);
        }
        int[] g=new int[s.length()];
        g[0]=s.charAt(0)=='0'?1:0;
        for (int i=1;i<s.length();i++){
            g[i]=Math.min(g[i-1],f[i-1])+(s.charAt(i)=='0'?1:0);
        }
        return Math.min(g[s.length()-1],f[s.length()-1]);
    }

    public static void main(String[] args) {
        System.out.println(new Solution926().minFlipsMonoIncr("00110"));
    }
}
